<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.LiShiTuiHuoDan"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>

<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
        <h1><spring:message code="message.list.YiQueRenTuiHuoDan"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
             <li class="active"><a href="#"><spring:message code="message.list.TuiHuoChuLi"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.list.YiQueRenTuiHuoDan"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="input">
                	<div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>" />
                    	</div>
                	<div class="textalign"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugCode" name="drugCode"  placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>" />
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.ShengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="compName" name="compName"  placeholder="<spring:message code="message.listForm.ShengChanQiYe"/>" />
                    </div>
                </div>
                 <div class="input" style="margin-top:3px">
                 	<div class="textalign1"><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="hospName" name="hospName"  placeholder="<spring:message code="message.listForm.yiLiaoJiGou"/>" />
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.TuiHuoDanHao"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="retCode" name="retCode"  placeholder="<spring:message code="message.listForm.TuiHuoDanHao"/>" />
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.PiCiHao"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="lotId" name="lotId"  placeholder="<spring:message code="message.listForm.PiCiHao"/>" />
                    </div>
                 </div>
                 <div class="input" style="margin-top:-5px">
                 	<div class="textalign1"><spring:message code="message.listForm.TuiHuoRiQi"/><spring:message code="message.yanZheng.maoHao"/></div>
	                <div class="boxinput"> 
                       <table style="width:100%">
                                <tr>
                                    <td style="width:50%">
                                        <input id="startDate" name="startDate" type="text" class="textinput" placeholder="yyyy-MM-dd11" 
											data-date-fmt="yyyy-MM-dd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'endDate\')}'})" />
                                    </td>
                                    <td>&nbsp;-&nbsp;</td>
                                    <td style="width:50%">
                                        <input id="endDate" name="endDate" type="text" class="textinput"  placeholder="yyyy-MM-dd" 
                                        data-date-fmt="yyyy-MM-dd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}'})" />
                                    </td>
                                </tr>
                            </table>
                    </div>
                    <div class="textalign" >
                    <button type="button" class="btn btn-success btn-sm" onclick="search()" id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
                    </div>   
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
  //绑定回车
    $('#drugName,#drugCode,#compName,#retCode,#lotId,#hospName,#startDate,#endDate').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectDicCompType').click();
        }
    });	
    $("#drugName").focus();//加载页面光标在第一个查询框内
    
        function showFocus(rowId) {
            $("#gridlist").resetSelection();
            $("#gridlist").setSelection(rowId);
        }
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "getReturnOrderHisDetail.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                shrinkToFit: false,
                height: 285,
                colNames: [
                           '<spring:message code="message.listForm.yaoPinBianMa"/>',
	                       '<spring:message code="message.listForm.tongYongMing"/>', 
	                       '<spring:message code="message.listForm.jiXing"/>',
	                       '<spring:message code="message.listForm.guiGe"/>',
	                       '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
	                       '<spring:message code="message.listForm.baoZhuangDanWei"/>', 
	                       '<spring:message code="message.listForm.caiZhi"/>',
	                       '<spring:message code="message.listForm.shengChanQiYe"/>',
	                       '<spring:message code="message.listForm.CaiGouJia"/>',
	                       '<spring:message code="message.listForm.TuiHuoShuLiang"/>',
                           '<spring:message code="message.listForm.TuiHuoYuanYin"/>',
                           '<spring:message code="message.lable.yiLiaoJiGouMingCheng"/>',
                           '<spring:message code="message.listForm.TuiHuoDanBianHao"/>',
                           '<spring:message code="message.listForm.PiCiHao"/>',
                           '<spring:message code="message.listForm.TuiHuoShiJian"/>',
                           '<spring:message code="message.listForm.TuiHuoRen"/>',
                           '<spring:message code="message.lable.status"/>',
                           '<spring:message code="message.listForm.QueRenShiJian"/>',
                           '<spring:message code="message.listForm.QueRenRen"/>',
                           '<spring:message code="message.listForm.QueRenBeiZhu"/>'
                           ],
                colModel: [
					    { name: 'drugCode', index: 'ship', width: 120, align: "center",sortable:false,
						    formatter:function(cellvalue, options, row){
						        return '<a href="javascript:showDrugInfo(\''+ row.drugId +'\');">'+cellvalue+'</a>';
						    }
						},
						{ name: 'drugName', index: 'name', width: 140, align: "left" ,sortable:false },
						{ name: 'formName', index: 'stock', width: 80 , align: "center",sortable:false},
						{ name: 'specName', index: 'ship', width: 80, align: "left" ,sortable:false},
						{ name: 'factor', index: 'ship', width: 80, align: "center" ,sortable:false},
						{ name: 'unit', index: 'ship', width: 40, align: "center" ,sortable:false},
						{ name: 'materialName', index: 'ship', width: 80, align: "left" ,sortable:false},
						{ name: 'compName', index: 'ship', width: 180, align: "left",sortable:false,
						    formatter:function(cellvalue, options, row){
						        return '<a href="javascript:showCompInfo(\''+ row.compId +'\');">'+cellvalue+'</a>';
						    }
					   },
                      
                       { name: 'proPrice', index: 'sdate', width: 60, align: "right",sortable:false},
                       { name: 'retCount', index: 'sdate', width: 70, align: "center",sortable:false},
                       { name: 'retReason', index: 'sdate', width: 80, align: "center",sortable:false},
                       { name: 'hospName', index: 'ship', width: 180,align:"left",sortable:false,
                           formatter:function(cellvalue, options, row){
                               return '<a href="javascript:showHospInfo(\''+ row.hospId +'\');">'+cellvalue+'</a>';
                           }
                       },
                       { name: 'retCode', index: 'sdate', width: 180, align: "center",sortable:false},
                       { name: 'lotId', index: 'sdate', width: 80, align: "center",sortable:false},
                       { name: 'submitTime', index: 'sdate', width: 140, align: "center",sortable:false},
                       { name: 'submitUserName', index: 'sdate', width: 160, align: "center",sortable:false},
                       { name: 'status', index: 'sdate', width: 80, align: "center",sortable:false},
                       { name: 'confirmTime', index: 'sdate', width: 140, align: "center",sortable:false},
                       { name: 'confirmUserName', index: 'sdate', width: 160, align: "center",sortable:false},
                       { name: 'confirmRemark', index: 'sdate', width: 180, align: "left",sortable:false}
                ],
                rowNum: 20,
                rowList: [10, 20,50,100],
                rownumbers: true,
                multiselect: false,
                pager: "#gridpage",
                viewrecords: true,
                gridComplete: function(){
               	 //序号列宽度自适应（参数为jqgridID）
                      autoRNWidth("gridlist");
                  	//数据只有一条时默认选中（参数为jqgridID）
                      selectByOneData("gridlist");
                },
                caption: "<spring:message code="message.list.YiQueRenTuiHuoDanLieBiao"/>",
                jsonReader: {
                    repeatitems: false,
                    id: "retDetailId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        /* 日期查询 */
        var date = new Date();
        date.setMonth(date.getMonth() - 1);
        $('#startDate').val(date.format("yyyy-MM-dd"));
        $('#endDate').val(new Date().format("yyyy-MM-dd"));
        
        
        
        /* 查询 */
        function search(page) {
            var retCode = $.trim($("#retCode").val());
            var lotId = $.trim($("#lotId").val());
            var drugCode = $.trim($("#drugCode").val());
            var drugName = $.trim($("#drugName").val());
            var compName = $.trim($("#compName").val());
            var hospName = $.trim($("#hospName").val());
            var startDate = $.trim($("#startDate").val());
            var endDate = $.trim($("#endDate").val());
            $("#gridlist").jqGrid("clearGridData");
                $("#gridlist").jqGrid('setGridParam',{  
                mtype: "POST",
                datatype:'json',
                postData:{"retCode":retCode, 
                          "lotId":lotId,
                          "drugCode":drugCode, 
                          "drugName":drugName,
                          "compName":compName, 
                          "hospName":hospName,
                          "startDate":startDate,
                          "endDate":endDate
                },
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
        
        /* 同意 */
        function agreeReturnConfirm(status) {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "<spring:message code="message.HN.alert.type"/>", "warn");
                return;
            }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                list.push({"retDetailId":rowId, "status":status});
            }
            $.post("agreeReturnConfirm.html", {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                    search(curpage);
                    $.HN.message.alert("操作成功！", "<spring:message code="message.HN.alert.type"/>", "success");
                } else {
                    $.HN.message.alert("操作失败！", "<spring:message code="message.HN.alert.type"/>", "error");
                }
            }, "json")
        }
        
        
        /* 拒绝 */
        function rejectReturnConfirm(status) {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "<spring:message code="message.HN.alert.type"/>", "warn");
                return;
            }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                list.push({"retDetailId":rowId, "status":status});
            }
            $.post("rejectReturnConfirm.html", {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                    search(curpage);
                    $.HN.message.alert("操作成功！", "<spring:message code="message.HN.alert.type"/>", "success");
                } else {
                    $.HN.message.alert("操作失败！", "<spring:message code="message.HN.alert.type"/>", "error");
                }
            }, "json")
        }
        
        
        
        //医疗机构信息弹窗
        function showHospInfo(hospId) {
            $.HN.dialog.open({
                "id": "showHospInfo", 
                "title": "<spring:message code="message.listForm.yiLiaoJiGouxinxi"/>", 
                "url": "${ctx}/stdHospInfo/hospInfoDetail.html?hospId="+hospId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }
        
        //药品信息弹窗
        function showDrugInfo(drugId) {
            $.HN.dialog.open({
                "id": "showDrugInfo", 
                "title": "<spring:message code="message.listForm.YaoPinXinXi"/>", 
                "url": "${ctx}/stdDrug/drugInfoDetail.html?drugId="+drugId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }
        
        //生产企业信息弹窗
        function showCompInfo(prodCompId) {
            $.HN.dialog.open({
                "id": "showCompInfo", 
                "title": "<spring:message code="message.listForm.ShengChanQiYeXinXi"/>", 
                "url": "${ctx}/stdCompinfo/toStdCompinfoDetail.html?compId="+prodCompId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }

        
    </script>
</body>
</html>